package com.jt.controller;


import com.jt.service.FileService;
import com.jt.vo.ImageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
public class FileController {
    @Autowired
    private FileService fileService;


    @RequestMapping("/file")
    public String file(MultipartFile fileImage) throws IOException {
        String dir="D:/image";
        File dirFile=new File(dir);
        if(!dirFile.exists()){
            dirFile.mkdirs();
        }
        String fileName=fileImage.getOriginalFilename();
        File imageFile=new File(dir+"/"+fileName);
        fileImage.transferTo(imageFile);
        return "文件上传成功！！！";
    }

    @RequestMapping("/pic/upload")
    public ImageVO uploadFile(MultipartFile uploadFile){
       // String url="https://img-blog.csdnimg.cn/20210301165428806.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE2ODA0ODQ3,size_16,color_FFFFFF,t_70";
        return fileService.uploadFile(uploadFile);
    }

}
